# -*- coding: utf-8 -*-
import sys
import os
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from datetime import datetime, timedelta
from Data.DataAchieve import *
from Data.DataOperate import *
from Util.Return import *
from Util.Process import *

if __name__ == '__main__':

    start_time = get_config("manage", "data_date")["start_time"]
    end_time = (datetime.strptime(start_time, "%Y-%m-%d") + timedelta(days=get_config("manage", "data_date")["interval"])).strftime("%Y-%m-%d")

    data_date = [start_time, end_time]
    data_area = get_config("config", "data_manage")["data_area"]
    data_list = get_config("config", "data_manage")["data_list"]
    INFO("INFO", "GET DATA from {start_time} to {end_time} for {data_area} in {data_list}".format(start_time=start_time, end_time=end_time, data_area=data_area, data_list=data_list))

    empty_temp_path()   # 清空目录
    for address in data_area:
        for dataset in data_list:
            get_all(dataset, address, data_date)
    INFO("INFO", "SUCCESS GET DATA from {start_time} to {end_time} for {data_area} in {data_list}".format(start_time=start_time, end_time=end_time, data_area=data_area, data_list=data_list))
    update_start_time((datetime.strptime(end_time, "%Y-%m-%d") + timedelta(days=1)).strftime("%Y-%m-%d"))   # 更新任务起始时间
